package com.purong.purong.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;

/**
 * 自定义高度的viewpapger
 */
public class BaseViewPager extends ViewPager {
	private boolean scrollable = true;

	public BaseViewPager(Context context) {
		super(context);
	}

	public BaseViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	/**
	 * 设置viewpager是否可以滚动
	 * 
	 * @param enable
	 */
	private ViewGroup parent;
	public void setScrollable(boolean enable,ViewGroup parent) {
		scrollable = enable;
		this.parent = parent;
	}

//	@Override
//	public boolean onInterceptTouchEvent(MotionEvent event) {
//		if (scrollable) {
//			return super.onInterceptTouchEvent(event);
//		} else {
//			return false;
//		}
//	}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
	if (parent != null) {
		parent.requestDisallowInterceptTouchEvent(true);
	}
	return super.dispatchTouchEvent(ev);
}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (parent != null) {
			parent.requestDisallowInterceptTouchEvent(true);
		}
		return super.onInterceptTouchEvent(ev);
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (parent != null) {
			parent.requestDisallowInterceptTouchEvent(true);
		}
		return super.onTouchEvent(ev);
	}
}